package com.dingding.service.usermangerservice.impl;

import org.apache.log4j.Logger;

import com.dingding.bean.databean.response.DataResponse;
import com.dingding.bean.entity.Vehicleaudit;
import com.dingding.bean.entity.Vehicleinfo;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.service.BaseService;
import com.dingding.service.usermangerservice.IVehicleAuditService;

/**
 * 
 * @ClassName: VehicleAuditServiceImpl
 * @Description: 车主审核记录
 * @author lijinchao
 * @date 2015-11-26 上午11:27:05
 * @version
 */
public class VehicleAuditServiceImpl extends BaseService implements
		IVehicleAuditService {
	
	private static final Logger log = Logger.getLogger(VehicleAuditServiceImpl.class);

	/**
	 * @Title: saveAncientRecord
	 * @Description: 重新认证时保存旧的数据
	 * @param vehicleinfo
	 *            旧的车主资料
	 * @author lijinchao
	 * @return boolean 是否保存成功
	 * @throws
	 */
	@Override
	public boolean saveAncientRecord(Vehicleinfo vehicleinfo) {

		// 转换记录bean
		Vehicleaudit vehicleaudit = this.getVehicleaudit(vehicleinfo);
		
		try {
			// 保存旧的资料
			super.vehicleAuditDao.save(vehicleaudit);
			return true;
		} catch (Exception e) {
			log.error("保存旧的车主认证资料时出现异常 类："+this.getClass()+" 方法：saveAncientRecord()", e);
		}
		
		return false;
	}

	/**
	 * @Title: getVehicleaudit
	 * @Description: 转换记录bean
	 * @param vehicleinfo 车主车辆信息
	 * @author lijinchao
	 * @return Vehicleaudit
	 * @throws
	 */
	private Vehicleaudit getVehicleaudit(Vehicleinfo vehicleinfo) {

		Vehicleaudit vehicleaudit = new Vehicleaudit();

		// 主键
		vehicleaudit.setVaId(ToolUtil.getUid());
		// 用户id
		if (vehicleinfo.getLoginId() != null) {
			vehicleaudit.setLoginId(vehicleinfo.getLoginId());
		}
		// 车牌号
		if (vehicleinfo.getLisencePlate() != null) {
			vehicleaudit.setLisencePlate(vehicleinfo.getLisencePlate());
		}
		// 车辆型号
		if (vehicleinfo.getVehicleModel() != null) {
			vehicleaudit.setVehicleModel(vehicleinfo.getVehicleModel());
		}
		// 车辆品牌
		if (vehicleinfo.getVehicleType() != null) {
			vehicleaudit.setVehicleType(vehicleinfo.getVehicleType());
		}
		// 车辆颜色
		if (vehicleinfo.getVehicleColor() != null) {
			vehicleaudit.setVehicleColor(vehicleinfo.getVehicleColor());
		}
		// 行驶证图片
		if (vehicleinfo.getXszImage() != null) {
			vehicleaudit.setXszImage(vehicleinfo.getXszImage());
		}
		// 驾驶证图片
		if (vehicleinfo.getJszImage() != null) {
			vehicleaudit.setJszImage(vehicleinfo.getJszImage());
		}
		// 车辆图片
		if (vehicleinfo.getVehicleImage() != null) {
			vehicleaudit.setVehicleImage(vehicleinfo.getVehicleImage());
		}
		// 提交时间
		if (vehicleinfo.getCreateTime() != null) {
			vehicleaudit.setCreateTime(vehicleinfo.getCreateTime());
		}
		// 审核状态(1：审核中  2：审核通过  3：审核未通过  4：车主重新认证)
		if (vehicleinfo.getVstatus() != null) {
			vehicleaudit.setVstatus(4);
		}
		// 行驶证审核评语
		if (vehicleinfo.getXszDescription() != null) {
			vehicleaudit.setXszDescription(vehicleinfo.getXszDescription());
		}
		// 驾驶证评语
		if (vehicleinfo.getJszDescription() != null) {
			vehicleaudit.setJszDescription(vehicleinfo.getJszDescription());
		}
		// 车辆图片评语
		if (vehicleinfo.getVehicleDescription() != null) {
			vehicleaudit.setVehicleDescription(vehicleinfo
					.getVehicleDescription());
		}
		// 其他评语
		if (vehicleinfo.getDescription() != null) {
			vehicleaudit.setDescription(vehicleinfo.getDescription());
		}

		return vehicleaudit;
	}

	@Override
	public void setStatus(DataResponse dataResponse, int status) {

	}

}
